#include <stdio.h>

void reverse(int a[], int left, int right, int k) {
    int temp;
    for (int i = left, j = right; i < left + k && i < j; ++i, --j) {
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}

/**
 * P35页，真题仿造-第1问，将数组A中的m+n个元素
 *
 * @param A
 * @param m
 * @param n
 */
void insertElement(int A[], int m, int n) {
    int total = 0;
    int i, j;
    int temp;
    for (i = m; i < m + n; ++i) {
        temp = A[i];
        for (j = i - 1; j >= 0 && temp < A[j]; --j) {
            A[j + 1] = A[j];
            total++;
        }
        A[j + 1] = temp;
    }
    printf("total times %d ", total);
}

void difference() {

}

int main() {
    int a[7] = {8, 9, 10, 2, 3, 4, 5};
    // reverse(a, 0, 4, 2);
    // moveP(a, 5, 3);
    insertElement(a, 3, 4);
    for (int loop = 0; loop < 7; loop++) {
        printf("%d ", a[loop]);
    }
    return 0;
}

